package com.great.medical.classify.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.great.medical.classify.db.model.Classify;
import com.great.medical.classify.service.ClassifyService;
import com.great.medical.common.ResultBody;
import com.great.medical.common.StatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/classify")
@Slf4j
@SuppressWarnings("unchecked")
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    @GetMapping("/getPageList")
    public ResultBody<IPage<Classify>> getPageList(@RequestParam(required = false) Map map) {
        return ResultBody.ok().data(classifyService.getPageList(map));
    }

    @GetMapping("/list")
    public ResultBody<List<Classify>> list() {
        final List<Classify> list = classifyService.lambdaQuery().eq(Classify::getStatus, StatusEnum.ENABLE.getCode()).list();
        return ResultBody.ok().data(list);
    }


    @PostMapping("/saveOrUpdate")
    public ResultBody<Void> saveOrUpdate(@RequestBody Classify classify) {
        classifyService.saveOrUpdate(classify);
        return ResultBody.ok();
    }

}
